
/*
 * ReportInsertServlet.java
 *
 * Created on 4 December, 2007, 3:43 PM
 */

import java.io.*;
import java.sql.ResultSet;
import java.util.*;

import javax.servlet.*;
import javax.servlet.http.*;


import pool.bean.Master_table_Bean;
import pool.bean.Property_details_Bean;
import pool.bean.Transaction_Bean;
import utility.CapitalChar;

import control.RequestParameter;

import guidatatag.TagInterface;
import utility.MasterPLOperations;
import guireportgenerator.MaxId;
import dbmanager.*;
/**
 *
 * @author wiki22
 * @version
 */
public class InsertServlet extends HttpServlet 
{
	/**
	 * 
	 */
	private static final long serialVersionUID = -4291969325902393437L;
	
	MasterPLOperations mpl;
    MaxId maxid;
    String name;
    
    int tempref = 0;
    
    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        doPost(request,response);
    }
    
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
     */
    @SuppressWarnings({ "unchecked", })
	protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
    {
        System.out.println("I'm in Insert servlet");
        HttpSession mysession = request.getSession();
        String username = (String)mysession.getAttribute("username");
        String password = (String)mysession.getAttribute("password");
        
        GetIdName get = new GetIdName();
        maxid = new MaxId();  
        
        mpl = new MasterPLOperations(username,password);                        
        name = request.getParameter("name");
        
        if(mpl.insertMaster(name))
        	mpl.setMaster(name);
        
        Enumeration<Object> enum1 = request.getParameterNames();
        
        try 
        {
			while(enum1.hasMoreElements())
			{
			    String param_name = (String)enum1.nextElement();            
			    
			    if(!(param_name.equalsIgnoreCase("name")||param_name.toLowerCase().equals("submit")||param_name.toLowerCase().equals("reset")))
			    {
			        String param_val = request.getParameter(param_name);
			        System.out.println(param_name+"   "+param_val);            
			        
			        if(!(param_val.equals(null)||param_val.trim().equals("")))
			        {
			        	 mpl.setNewProperty(name, param_name, param_val,String.valueOf(tempref));
		                    tempref++;	                    
			        }
			    }
			}
			
			mpl.insertProperty();
			response.sendRedirect("Response");
		}
        catch (Exception e)
        {
			e.printStackTrace();
		}
        finally
        {
        	
        }
    }    
}
